package com.wzgl.core.baseModel;

import java.text.SimpleDateFormat;

import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.IDataLoader;
import com.wzgl.core.base.JModel;
import com.wzgl.message.MessageKit;

@SuppressWarnings("serial")
public class BaseFinishurl <M extends BaseFinishurl<M>> extends JModel<M> implements IBean{
	public static final String CACHE_NAME = "finishurl";
	public static final String METADATA_TYPE = "finishurl";

	public static final String ACTION_ADD = "finishurl:add";
	public static final String ACTION_DELETE = "finishurl:delete";
	public static final String ACTION_UPDATE = "finishurl:update";
	
	public void removeCache(Object key){
		if(key == null) return;
		CacheKit.remove(CACHE_NAME, key);
	}

	public void putCache(Object key,Object value){
		CacheKit.put(CACHE_NAME, key, value);
	}

	public M getCache(Object key){
		return CacheKit.get(CACHE_NAME, key);
	}

	public M getCache(Object key,IDataLoader dataloader){
		return CacheKit.get(CACHE_NAME, key, dataloader);
	}
	
	@Override
	public boolean save() {
		boolean saved = super.save();
		if (saved) { MessageKit.sendMessage(ACTION_ADD, this); }
		return saved;
	}

	@Override
	public boolean delete() {
		boolean deleted = super.delete();
		if (deleted) { MessageKit.sendMessage(ACTION_DELETE, this); }
		return deleted;
	}

	@Override
	public boolean deleteById(Object idValue) {
		boolean deleted = super.deleteById(idValue);
		if (deleted) { MessageKit.sendMessage(ACTION_DELETE, this); }
		return deleted;
	}

	@Override
	public boolean update() {
		boolean update = super.update();
		if (update) { MessageKit.sendMessage(ACTION_UPDATE, this); }
		return update;
	}
	
	public void setFid(java.lang.String id) {
		set("fid", id);
	}
	public java.lang.String getFid() {
		Object id = get("fid");
		if (id == null)
			return null;
		return id.toString();
	}
	
	/**
	 * url
	 * @return
	 */
	public java.lang.String getFurl() {
		return get("furl");
	}

	public void setFurl(java.lang.String furl) {
		set("furl", furl);
	}
	
	/**
	 * 缓存的日期
	 */
	public String getFdate() {
		java.util.Date time = get("fdate");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String s = sdf.format(time);
		return s;
	}
	public void setFdate(java.util.Date fdate) {
		set("fdate", fdate);
	}


}
